package com.tricky.demo.rabbit.service;

import com.tricky.demo.rabbit.config.EnumRabbitQueue;
import com.tricky.demo.rabbit.msg.DemoDataMsg;
import com.tricky.demo.rabbit.msg.DemoNumberMsg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 测试
 *
 * @Autor Shadow 2020/10/23
 * @Date 2020-10-23 14:36:50
 */
@Service
public class TestRabbitService {
	private static Logger logger = LoggerFactory.getLogger(TestRabbitService.class);

	@Autowired
	private AmqpTemplate amqpTemplate;

	/**
	 * 发送一个test消息
	 *
	 * @param dt
	 */
	public void sendData(String dt) {
		DemoDataMsg msg = new DemoDataMsg();
		msg.setData(dt);
		amqpTemplate.convertAndSend(EnumRabbitQueue.Demo.getExchange(), EnumRabbitQueue.Demo.getRouteKey(), msg, (message) -> message);
	}


	/**
	 * 发送一个test消息
	 *
	 * @param dt
	 */
	public void sendNumber(String dt) {
		DemoNumberMsg msg = new DemoNumberMsg();
		msg.setNumber(Long.parseLong(dt));
		amqpTemplate.convertAndSend(EnumRabbitQueue.Demo.getExchange(), EnumRabbitQueue.Demo.getRouteKey(), msg, (message) -> message);
	}
}
